Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@swc/types
Advanced tools
The @swc/types package provides TypeScript type definitions for the AST (Abstract Syntax Tree) nodes used by SWC, a super-fast compiler written in Rust. It is primarily used by developers working on tooling for JavaScript and TypeScript, such as linters, formatters, and compilers. By offering a structured way to represent code, it enables programmatic analysis, manipulation, and generation of JavaScript and TypeScript code.
Defining AST Nodes
This code sample demonstrates how to define a simple AST node for a variable declaration in JavaScript using the types provided by @swc/types. It represents a variable `x` being declared and initialized with the value `10`.
{
"type": "VariableDeclaration",
"kind": "var",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "x"
},
"init": {
"type": "Literal",
"value": 10,
"raw": "10"
}
}
]
}
Manipulating AST Nodes
This function takes an AST node and, if it is a numeric literal, doubles its value. It showcases how @swc/types can be used to manipulate AST nodes programmatically.
function updateLiteralValue(node) {
if (node.type === 'Literal' && typeof node.value === 'number') {
node.value *= 2;
}
return node;
}
Similar to @swc/types, @babel/types provides definitions and constructors for AST nodes for use with Babel. While both packages serve a similar purpose in providing tools for AST manipulation, @babel/types is tailored for the Babel ecosystem, which might make it more suitable for projects already using Babel for transpilation.
The TypeScript package itself includes utilities for working with TypeScript ASTs. While @swc/types is focused on SWC's AST format, the TypeScript package is essential for projects that need to work directly with TypeScript codebases, offering more comprehensive support for TypeScript-specific features.
Typings for @swc/core
APIs. This is a separate package because SWC is used by various tools but not all of them want to depend on @swc/core
.
This package is very cheap, so feel free to depend on this.
FAQs
Typings for the swc project.
The npm package @swc/types receives a total of 5,141,879 weekly downloads. As such, @swc/types popularity was classified as popular.
We found that @swc/types demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.